﻿namespace FFF.Test.Entity.Demo.Function
{
    using System;
    using System.Collections.Generic;
    using System.Data.SqlClient;
    using System.IO;
    using System.Text;
    using Microsoft.Extensions.Configuration;
    using FFF.Test.Util.Configuration;
    using FFF.Test.Util.Consts;
    using Ydm.Helper;

	/// <summary>
    /// fn_Demo_GetHello函数
    /// </summary>
    public class FnDemoGetHello
    {        
        /// <summary>
        /// @Str
        /// </summary>
        public string @Str { get; set; } 
        
        /// <summary>
        /// 获取单个值
        /// </summary>
        /// <typeparam name="T">值得类型</typeparam>
        /// <returns>单个值</returns>
        public T ExecuteScalar<T>()
        {
            var conStr = AppConfigConsts.ConStr;
            string sql = this.GetSql();
            return DBHelper.ExecuteScalar<T>(conStr, sql, null);
        }

        /// <summary>
        /// 获取sql
        /// </summary>
        /// <returns>获取sqlstr</returns>
        private string GetSql()
        {
            string sql = "SELECT dbo.fn_Demo_GetHello( ";
            sql += $"'{this.@Str}',";
            sql = sql.Substring(0, sql.Length - 1);
            sql += ");";
            return sql;
        }
    }
}
